package com.bestvike.stone.core.util.area;

import com.bestvike.linq.exception.ArgumentNullException;
import com.bestvike.stone.core.collection.KeyedCollection;
import org.springframework.util.Assert;

/**
 * 街道级行政区集合
 * Created by 许崇雷 on 2019-01-09.
 */
public final class TownCollection extends KeyedCollection<String, Town> {
    private final County county;

    TownCollection(County county) {
        Assert.notNull(county, "county can not be null");
        this.county = county;
    }

    @Override
    protected String getKeyForItem(Town town) {
        return town.getCode();
    }

    @Override
    public boolean add(Town town) {
        if (town == null)
            throw new ArgumentNullException("town");
        town.setCounty(this.county);
        return super.add(town);
    }
}
